package com.ctcc;

import com.ctcc.util.AESEncryptor;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.TimeUnit;

@EnableScheduling//加入定时
@SpringBootApplication
public class SpringbootctccApplication {


    @Bean
    AESEncryptor aesEncryptor(@Value("aesKey")String aesKey){
//        return new AESEncryptor(aesKey);
        return new AESEncryptor("kKkaIosUxRVDSBVB");
    }

    public static void main(String[] args) {

        SpringApplication.run(SpringbootctccApplication.class, args);

    }

    @Bean(name = "tokenCache")
    Cache<String,String> tokenCache() {
        return CacheBuilder.newBuilder()
                .expireAfterWrite(7200, TimeUnit.SECONDS)
                .initialCapacity(1)
                .build();
    }

    @Bean
    public OkHttpClient okHttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(httpLoggingInterceptor);
        return builder.build();
    }
}
